"use strict";
cc._RF.push(module, '108d3NpbclLSZuXABlsHH9C', 'wxApi');
// scripts/engines/services/miniGameContent/wx/wxApi.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var miniApp_1 = require("../miniApp");
var umaConfig_1 = require("../../../../sdk/uma/src/umaConfig");
var wx = window['wx'];
var WxApi = /** @class */ (function (_super) {
    __extends(WxApi, _super);
    function WxApi() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.m_appId = 'wx2edf2ac52464dcae';
        _this.m_secret = '1c7ea66258fe921c8f8a2dd229756e5c';
        _this.m_adUnitId = 'adunit-3f5c64c3e81acb30';
        //微信视频广告组件
        _this.m_rewardedVideoAd = null;
        return _this;
    }
    WxApi.prototype.drawHead = function (headUrl) {
        throw new Error("Method not implemented.");
    };
    WxApi.prototype.fullScreenVideo = function () {
        throw new Error("Method not implemented.");
    };
    WxApi.prototype.LocalInBlockCityList = function () {
        return false;
    };
    WxApi.prototype.vibrate = function (type) {
    };
    WxApi.prototype.getUserInfo = function (params) {
        wx.getUserInfo(params);
    };
    WxApi.prototype.showToast = function (params) {
        wx.showToast(params);
    };
    WxApi.prototype.showLoading = function (params) {
        wx.showLoading(params);
    };
    WxApi.prototype.hideLoading = function () {
        wx.hideLoading();
    };
    WxApi.prototype.preCreateUnits = function () {
        wx.showShareMenu({
        // withShareTicket: true,
        });
        this.createRewardedVideoAd({ adUnitId: this.m_adUnitId });
        //
        console.log('wx 初始化友盟参数', typeof uma);
        uma.init({
            appKey: umaConfig_1.UMA_SDK.APP_KEY,
            useOpenid: false,
            autoGetOpenid: true,
            debug: true,
            uploadUserInfo: true // 上传用户信息，上传后可以看到有用户头像和昵称的分享信息
        });
    };
    WxApi.prototype.loadAndShowVideoAd = function (successCallback, errorCallback, completeCallback) {
        var _this = this;
        if (this.m_rewardedVideoAd == null) {
            console.error('微信广告视频组件不存在');
            errorCallback(null);
            return;
        }
        this.m_rewardedVideoAd.load().then(function () {
            _this.m_rewardedVideoAd.show().then(function () {
                _this.m_rewardedVideoAd.onClose(function (res) {
                    if (res && res.isEnded) {
                        successCallback();
                    }
                    else {
                        errorCallback('视频未播放完');
                    }
                    completeCallback && completeCallback();
                });
            }).catch(function () {
                /**
                 // 用户触发广告后，显示激励视频广告
                 videoAd.show().catch(() => {
                    // 失败重试
                    videoAd.load()
                        .then(() => videoAd.show())
                        .catch(err => {
                            console.log('激励视频 广告显示失败')
                        })
                })
                 */
                errorCallback('视频显示错误');
                completeCallback && completeCallback();
            });
        }).catch(function () {
            errorCallback('视频加载错误');
            completeCallback && completeCallback();
        });
    };
    WxApi.prototype.login = function (params) {
        wx.login(params);
    };
    WxApi.prototype.authorize = function (params) {
        params.scope = params.scope || 'scope.userInfo';
        wx.authorize(params);
    };
    WxApi.prototype.validAppId = function () {
        if (wx.getAccountInfoSync().miniProgram.appId != this.m_appId) {
            console.error('非法盗用游戏资源将受到法律制裁');
            cc.game.end();
            throw '非法盗用游戏资源将受到法律制裁';
        }
    };
    WxApi.prototype.isHaveShareVideo = function () {
        return false;
    };
    WxApi.prototype.gameRecordStart = function (params, onStart) {
        if (!this.isHaveShareVideo())
            return;
        throw new Error("#112 微信录屏功能.");
    };
    WxApi.prototype.gameRecordStop = function () {
        if (!this.isHaveShareVideo())
            return false;
        return true;
    };
    WxApi.prototype.shareGameRecordVideo = function (successCb, failCb) {
        if (!this.isHaveShareVideo())
            return;
        throw new Error("#120 微信分享录屏功能.");
    };
    WxApi.prototype.isProduction = function () {
        return true;
    };
    WxApi.prototype.reportAnalytics = function (eventKey, data) {
        console.log('wx 发送埋点', eventKey, data);
        // wx.reportMonitor(eventKey, data);
        console.log('wx 上报友盟事件 trackEvent', eventKey, data);
        uma.trackEvent(eventKey, data);
    };
    WxApi.prototype.clearMemory = function () {
        wx.triggerGC();
    };
    WxApi.prototype.shareAppMessage = function (args) {
        var title = '';
        if (args) {
            title = args.title;
        }
        wx.shareAppMessage({
            title: title,
        });
    };
    WxApi.prototype.createRewardedVideoAd = function (param) {
        this.m_rewardedVideoAd = wx.createRewardedVideoAd(param);
    };
    WxApi.prototype.PlayLastRecordSound = function (scale, successCb, errorCb) {
    };
    WxApi.prototype.StartRecordSound = function () {
    };
    WxApi.prototype.StopRecordSound = function (successCallback) {
    };
    WxApi.prototype.addShortcut = function () {
        return Promise.resolve(false);
    };
    WxApi.prototype.createMoreGameBtn = function () {
    };
    WxApi.prototype.drawUrlImage = function (url, overCb) {
        var image = wx.createImage();
        image.onload = function () {
            var texture = new cc.Texture2D();
            texture.initWithElement(image);
            texture.handleLoadedTexture();
            overCb(new cc.SpriteFrame(texture));
        };
        image.src = url;
    };
    WxApi.prototype.getShareVideoRank = function (sortType, successCb) {
    };
    WxApi.prototype.hideBanner = function () {
    };
    WxApi.prototype.operateGameLive = function () {
    };
    WxApi.prototype.reportAdClickNativeAd = function () {
    };
    WxApi.prototype.showAddFavoriteGuide = function (successCallback, failCallback, completeCallback) {
    };
    WxApi.prototype.showBannerAD = function (node, successCallback, errorCallback, onCloseCallBack, setBannerPosition) {
    };
    WxApi.prototype.showInterstitialAd = function (onAdClose, onFailed) {
    };
    WxApi.prototype.showNativeAd = function (successCallback, errorCallback, completeCallback) {
    };
    WxApi.prototype.showVideo = function (videoUrl) {
    };
    WxApi.prototype.subscribeMessage = function (successCallback, failCallback, completeCallback) {
    };
    WxApi.prototype.showModal = function (params) {
    };
    WxApi.prototype.commitRank = function (rankId, score) {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, Promise.resolve(false)];
            });
        });
    };
    WxApi.prototype.showRank = function (rankId) {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, Promise.resolve(false)];
            });
        });
    };
    //
    WxApi.prototype.navigateToMiniGame = function (appId, successCallback, failCallback) {
        //
        wx.navigateToMiniProgram({
            appId: appId,
            success: function (res) {
                successCallback && successCallback();
            },
            fail: function (res) {
                failCallback && failCallback();
            }
        });
    };
    return WxApi;
}(miniApp_1.default));
exports.default = WxApi;

cc._RF.pop();